import path from 'path';
import { OrmOptions, JwtOptions, CryptOptions, KoaServerOptions } from '../types/index';

/**
 * typeorm配置
 */
const ormconfig: OrmOptions = {
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'root',
  password: '123456',
  database: 'test',
  timezone: 'Z',
  //确保每次运行应用程序时实体都将与数据库同步
  synchronize: false,
  //logging: false,
  logging: ['query'],
  entities: ['src/entity/**/*.entity.ts']
};

/**
 * jwt配置
 * expiresIn属性值为数字时，以秒为单位；
 * 值为字符串不加单位时，以毫秒为单位。
 */
const jwtconfig: JwtOptions = {
  secret: 'jsonwebtoken',
  expiresIn: 60 * 5
};

/**
 * 数据加密配置
 */
const cryptconfig: CryptOptions = {
  algorithm: 'aes-128-cbc',
  key: 'typeormjwtnodejs',
  iv: '0123456789abcdef'
};

/**
 * koa服务配置
 */
const serverconfig: KoaServerOptions = {
  port: 3000,
  options: {
    // // 启用校验
    // validation: true,
    // 路由前缀
    routePrefix: '/api/v1',
    controllers: [path.resolve(__dirname, '../controllers/*.controller.ts')],
    middlewares: [path.resolve(__dirname, '../middlewares/*.middleware.ts')],
    interceptors: [path.resolve(__dirname, '../interceptors/*.interceptor.ts')]
  }
};

/**
 * 不需要验证的接口
 */
const unlesspath: Array<RegExp> = [/\/login/, /\/register/, /\/file/];

export { ormconfig, jwtconfig, cryptconfig, serverconfig, unlesspath };
